package com.kun.lagou.commodity.service;

import com.kun.lagou.commodity.api.dto.CommodityInfo;
import com.kun.lagou.commodity.dao.CommodityDao;
import com.kun.lagou.commodity.model.CommodityModel;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 */
@Service
@RequiredArgsConstructor
public class CommodityService {
    private final CommodityDao commodityDao;

    /**
     * 根据商品ID查询商品信息
     * @param id
     * @return
     */
    public CommodityInfo getById(long id) {
        CommodityModel commodityModel = commodityDao.findById(id).orElse(null);
        if(commodityModel != null) {
            CommodityInfo info = new CommodityInfo();
            BeanUtils.copyProperties(commodityModel, info);
            return info;
        } else {
            return null;
        }
    }
}
